package cn.monkey.state.core;


import java.util.function.Supplier;

public interface State {

    String code();

    StateGroup getStateGroup();

    default boolean canAutoUpdate() {
        return true;
    }

    default StateContext getStateContext() {
        return this.getStateGroup().getStateContext();
    }

    void init(Supplier<Long> timer) throws Throwable;

    void onInitError(Supplier<Long> timer, Throwable e);

    void fireEvent(Supplier<Long> timer, Object event) throws Throwable;

    void onFireEventError(Supplier<Long> timer, Object event, Throwable e);

    void update(Supplier<Long> timer, StateInfo stateInfo) throws Throwable;

    void onUpdateError(Supplier<Long> timer, StateInfo stateInfo, Throwable e);

    String finish(Supplier<Long> timer) throws Throwable;

    String onFinishError(Supplier<Long> timer, Throwable e);
}
